package com.rs2hd.content;

import com.rs2hd.model.Player;
import javax.swing.Timer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Food {
	private final Player p;
	private boolean canEat = true;
	private transient Timer foodTimer;
	private transient final int[] foodData = {391, 385, 397, 315, 319, 325, 329, 339, 333, 347,351, 355, 361, 365, 7946, 379, 373, 3151, 337, 3144, 2149, 5003, 3381};
	public final boolean isFood(int foodId) {
		for (int i = 0; foodData.length > 0; i++) {
			if (i > foodData.length || this == null) {
				return false;
			}
			if (foodId == foodData[i]) {
				return true;
			}
		}
		return false;
	}
	private final void setEat(boolean bool) {
		this.canEat = bool;
	}
	public Food(final Player player) {
		this.p = player;
	}
	public final int getHeal(final int foodId) {
		switch(foodId) {
		case 391: return 22;//Mantas
		case 385: return 20;//Shark
		case 397: return 20;//Sea turtle
		case 315: return 3;//Shrimp
		case 319: return 1;//Anchovies
		case 325: return 4;//Sardine
		case 329: return 9;//Salmon
		case 339: return 9;//Cod
		case 333: return 7;//Trout
		case 347: return 7;//Herring
		case 351: return 7;//Pike
		case 355: return 5;//Mackerel
		case 361: return 10;//Tuna
		case 365: return 13;//Bass
		case 7946: return 16;//MonkFish
		case 379: return 12;//Lobster
		case 373: return 14;//Swordfish
		case 3151: return 3;//Karambwanji
		case 337: return 6;//Giant carp
		case 3144: return 18;//Cooked karambwan
		case 2149: return 11;//Lava eel
		case 5003: return 10;//Cava eel
		case 3381: return 6; //Cooked slimy eel
		default: return 0;
		}
	}
	public final String getString(final int foodId) {
		switch(foodId) {
		case 391: return "Mantas Ray";
		case 385: return "Shark";
		case 397: return "Sea turtle";
		case 315: return "Shrimp";
		case 319: return "Anchovies";
		case 325: return "Sardine";
		case 329: return "Salmon";
		case 339: return "Cod";
		case 333: return "Trout";
		case 347: return "Herring";
		case 351: return "Pike";
		case 355: return "Mackerel";
		case 361: return "Tuna";
		case 365: return "Bass";
		case 7946: return "Monkfish";
		case 379: return "Lobster";
		case 373: return "Swordfish";
		case 3151: return "Karambwanji";
		case 337: return "Giant carp";
		case 3144: return "Cooked karambwan";
		case 2149: return "Lava eel";
		case 5003: return "Cave eel";
		case 3381: return "Cooked slimy eel";
		default: return "Null";
		}
	}
	public final void eat(final Player p, final int foodId) {
		if (canEat) {
			System.out.println("WORKS");
			p.getCombat().combatDelay += 3;
			setEat(false);
			getPlayer().animate(829);
			getPlayer().getSkills().heal(getHeal(foodId));
			getPlayer().getActionSender().sendMessage("You eat the " + getString(foodId) + ".");
			getPlayer().getInventory().deleteItem(foodId, 1);
			foodTimer = new Timer(1900, new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					setEat(true);
				}
			});
			foodTimer.setRepeats(false);
			foodTimer.start();
		}
	}

	public final Player getPlayer() {
		return p;
	}
}
